//
//  THLayoutHeader.h
//  MengLiao
//
//  Created by xiuxin on 2022/7/15.
//  Copyright © 2022 BaseBusiness. All rights reserved.
//

#ifndef THLayoutHeader_h
#define THLayoutHeader_h


#import "UIDevice+Resolutions.h"//为了使用[UIDevice is_XDevice]方法

//防止系统设置uiscrollview的offset
#define KDisableInsetAdjustment(scroll) \
SEL adjustBehaviorSel = NSSelectorFromString(@"setContentInsetAdjustmentBehavior:");\
if ([scroll respondsToSelector:adjustBehaviorSel])\
{\
    NSInvocation * invocation = [NSInvocation invocationWithMethodSignature:[UIScrollView instanceMethodSignatureForSelector:adjustBehaviorSel]];\
    [invocation setSelector:adjustBehaviorSel];\
    [invocation setTarget:scroll];\
    NSInteger value = 2;\
    [invocation setArgument:&value atIndex:2];\
    [invocation invoke];\
}\

//UIWindow的安全区域Insets
#define KSafeAreaInsets ({\
UIEdgeInsets insets = UIEdgeInsetsZero;\
SEL safeAreaSel = NSSelectorFromString(@"safeAreaInsets");\
if ([[UIApplication sharedApplication].keyWindow respondsToSelector:safeAreaSel])\
{\
NSMethodSignature * methodSignature = [UIWindow instanceMethodSignatureForSelector:safeAreaSel];\
NSInvocation * invocation = [NSInvocation invocationWithMethodSignature:methodSignature];\
[invocation setSelector:safeAreaSel];\
[invocation setTarget:[UIApplication sharedApplication].keyWindow];\
[invocation invoke];\
[invocation getReturnValue:&insets];\
}\
insets;\
})

#define KAPPIconImage   [UIImage imageNamed:[[[[NSBundle mainBundle] infoDictionary] valueForKeyPath:@"CFBundleIcons.CFBundlePrimaryIcon.CFBundleIconFiles"] lastObject]]

#define KAPPName ({\
NSString *appName = [[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleDisplayName"];\
if (!appName) {\
    appName = [[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleName"];\
}\
appName;\
})

//主窗口的宽、高
#define kMainScreenWidth  MainScreenWidth()
#define kMainScreenHeight MainScreenHeight()

#define Width            [UIScreen mainScreen].bounds.size.width
#define Height           [UIScreen mainScreen].bounds.size.height

//以6的屏幕为基准的缩放比率
#define kSizeRate  (kMainScreenWidth/375.0)

#define KRelative(a)        (roundf((a) * ([UIScreen mainScreen].bounds.size.width /  750.0f) * [UIScreen mainScreen].scale) / [UIScreen mainScreen].scale)

#define kSizeRateTo(a)        (roundf((a) * ([UIScreen mainScreen].bounds.size.width /  375.0f) * [UIScreen mainScreen].scale) / [UIScreen mainScreen].scale)

//tabBar高度
#define kTabBarHeight          IPhoneX_Normal(83.0f,49.0f)  //  49 -> 83
//状态栏高度
#define kStatusBarHeight       [UIApplication sharedApplication].statusBarFrame.size.height  //  20 44  -->88

// navBar 的高度
#define KNavH             (kStatusBarHeight + 44)

//iPhoneX以上的安全区域
#define kSafeAeraHeight      IPhoneX_Normal(34,0)

#define IPhoneX_Normal(a,b) ([UIDevice is_XDevice] ? a:b)


#define KIsiPhoneX        (([[UIApplication sharedApplication] statusBarFrame].size.height > 20))

//适配宏_高
#define AD_HEIGHT(S)      ([UIScreen mainScreen].bounds.size.height / ((KIsiPhoneX ? Height : 667.0) / (S)))

//适配宏_宽
#define AD_WIDTH(S)       ([UIScreen mainScreen].bounds.size.width / ((KIsiPhoneX ? Width : 375.0) / (S)))



#define KLineHeight             (1.0f / [UIScreen mainScreen].scale)

static __inline__ CGFloat MainScreenWidth(){
    return UIInterfaceOrientationIsPortrait([UIApplication sharedApplication].statusBarOrientation) ? [UIScreen mainScreen].bounds.size.width : [UIScreen mainScreen].bounds.size.height;
}
static __inline__ CGFloat MainScreenHeight(){
    return UIInterfaceOrientationIsPortrait([UIApplication sharedApplication].statusBarOrientation) ? [UIScreen mainScreen].bounds.size.height : [UIScreen mainScreen].bounds.size.width;
}

#endif /* THLayoutHeader_h */
